-- CAN_USE_SUMMON_PROPERTY
-- 判断能否使用对召唤兽起效的道具

-- 判断使用道具的需求
-- @param user      玩家对象
-- @param classId   道具id
return function(user, classId)
    local dbase = PropertyM.query(classId, "dbase") or {};
    local summon_require = dbase["summon_require"] or 0;
    local msg = PropertyM.query(classId, "fail_tip") or "";

    if summon_require == 1 then
        local summonInfo = ME.user.dbase:query("summon");
        -- 当前没有召唤兽
        if not summonInfo then
            return msg;
        end

        local args = PropertyM.query(classId, "args");
        local value = {};
        if args["summon_attrib"] ~= nil then
            value = args["summon_attrib"];
        elseif args["summon_attrib2"] ~= nil then
            value = args["summon_attrib2"];
        end

        if #value <= 0 then
            return msg;
        end

        for pos, data in pairs(summonInfo) do
            -- 如果是目标召唤兽
            local summonId = data["class_id"];
            local grid = DungeonM.getGridByPos(pos);
            local summon = grid.summon;
            if summonId == value[1] and summon and not summon:isDead() then
                if "hp" == value[2] then
                    local maxHp = SummonM.query(value[1], "max_hp");
                    local curHp = summon:queryAttrib("hp");

                    if curHp >= maxHp then
                        return msg;
                    end
                end
            end
        end
    end

    return true;
end
